package com.databasteknik.krustykookiez;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JTabbedPane;



public class GUI {

	/**
	 * @param args
	 */
		private Database db;
		public GUI(Database db){
			this.db = db;
			if (db.openConnection("db49", "erikerik")) {
				JFrame frame = new JFrame("Krusty kookies");
				JTabbedPane tabbedPane = new JTabbedPane();
				
				
				Production pPane = new Production(db);
				Search sPane = new Search(db);
				Blocking bPane = new Blocking(db);
				
				tabbedPane.addTab("Production", null, pPane, "Produce pallets");
				tabbedPane.addTab("Search", sPane);
				tabbedPane.addTab("Blocking", bPane);
				
				tabbedPane.setSelectedIndex(0);
				
				frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
				;
				frame.addWindowListener(new WindowHandler());
				
				frame.setSize(800, 600);
				frame.setVisible(true);
				
			}

	}
	

	/**
	 * WindowHandler is a listener class, called when the user exits the
	 * application.
	 */
	class WindowHandler extends WindowAdapter {
		/**
		 * Called when the user exits the application. Closes the connection to
		 * the database.
		 * 
		 * @param e
		 *            The window event (not used).
		 */
		public void windowClosing(WindowEvent e) {
			db.closeConnection();
			System.exit(0);
		}
	}

}
